//
//  MCHongBaoDataModel.m
//  XDYL
//
//  Created by MC on 2018/3/27.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCHongBaoDataModel.h"
#import "MCCheckUserGrabMoneyModel.h"
#import "MCMineInfoModel.h"

@implementation MCHongBaoDataModel
singleton_m(MCHongBaoDataModel)

-(NSMutableArray *)hongBaoMarray{
    if (!_hongBaoMarray) {
        _hongBaoMarray=[[NSMutableArray alloc]init];
    }
    return _hongBaoMarray;
}

-(void)HB_RemoveObjectAtIndex:(NSUInteger)index{
    if (self.hongBaoMarray.count>0) {
        [self.hongBaoMarray removeObjectAtIndex:index];
    }
    if ((index+1)>self.hongBaoMarray.count) {
//        self.index=0;
    }
}

-(void)setDataWithArr:(NSArray *)arr{
    if (arr.count>0) {
        if (arr.count==self.hongBaoMarray.count) {
            return;
        }
    }else{
        self.index=0;
    }
    [self.hongBaoMarray removeAllObjects];
//    if (arr>0) {
        self.index=0;
//    }
    for (NSDictionary * temp in arr) {
        MCCheckUserGrabModel * model = [[MCCheckUserGrabModel alloc]init];
        model.Name=temp[@"Name"];
        model.RedEnvelopId=temp[@"RedEnvelopId"];
        model.SendName=temp[@"SendName"];
        [self.hongBaoMarray addObject:model];
    }
    
}

+(BOOL)isOpen_All_HB{
    //    1开启
    NSString * Red_Envelopes_IsOpen = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:MCRed_Envelopes_IsOpen]];
    
    if ([Red_Envelopes_IsOpen isEqualToString:@"1"]) {
        
        return YES;
    }else{
        return NO;
    }
}


+(BOOL)isOpenHB{
    //    1开启   &&  <=级别  &&    >=返点
    //    1开启       空            空
    BOOL isProxy_Level = YES,isRebate = YES;
    NSString * Red_Envelopes_IsOpen = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:MCRed_Envelopes_IsOpen]];
    NSString * Proxy_Level = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:MCProxy_Level]];
    NSString * Rebate = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:MCRebate]];
    MCMineInfoModel * mineModel = [MCMineInfoModel sharedMCMineInfoModel];
    NSString * UserLevel =  [NSString stringWithFormat:@"%@",mineModel.UserLevel];
    NSString * MyRebate = [NSString stringWithFormat:@"%@",mineModel.MyRebate];
    
    if (![Red_Envelopes_IsOpen isEqualToString:@"1"]) {
        return NO;
    }
    
    if ([Proxy_Level integerValue]>0) {
        if ([MyRebate integerValue]>=[Rebate integerValue]) {
        }else{
            isProxy_Level=NO;
        }
    }
    
    if ([Rebate integerValue]>0) {
        if ([UserLevel integerValue]<=[Proxy_Level integerValue]) {
        }else{
            isRebate=NO;
        }
    }
    
    if (isProxy_Level&&isRebate) {
        return YES;
    }
    return NO;

}
-(BOOL)isShouldRefreashHongBaoData{
    
//    if ([MCHongBaoDataModel isOpenHB]) {
//
//    }else{
//        return NO;
//    }

    if (!self.index) {
        self.index=0;
    }
    
    if (self.hongBaoMarray.count<1) {
        return YES;
    }
    if (self.index >= (self.hongBaoMarray.count-1)) {
        return YES;
    }
    
    return NO;
}

@end

















